//
//  tabBarBottomView.m
//  yiYuanDuoBao
//
//  Created by 罗李苏 on 16/11/23.
//  Copyright © 2016年 罗李苏. All rights reserved.
//

#import "tabBarBottomView.h"
#import "tabBatBtn.h"

@interface tabBarBottomView ()

@property (nonatomic, weak) UIButton *selectedBtn;

@end
@implementation tabBarBottomView
- (void)btnClick:(UIButton *)btn{

    self.selectedBtn.selected = NO;
    btn.selected = YES;
    self.selectedBtn = btn;
    
    //通过Block通知tabBar跳转控制器
    if (self.go2VcBlock != nil) {
        self.go2VcBlock(btn.tag);
    }
}
//MARK:设置子控件(按钮)的frame
- (void)layoutSubviews{

    [super layoutSubviews];
//    CGFloat W = self.frame.size.width / self.subviews.count;
    CGFloat W = 24;
//    CGFloat H = self.frame.size.height;
    CGFloat H = 40;
//    CGFloat Y = 0;
    CGFloat Y = (self.frame.size.height - H) / 2;
    CGFloat margin = 37;
    CGFloat margin1 = ([UIScreen mainScreen].bounds.size.width - 2 * margin - 4 * W) / (self.subviews.count - 1);
    [self.subviews enumerateObjectsUsingBlock:^(__kindof tabBatBtn * _Nonnull btn, NSUInteger idx, BOOL * _Nonnull stop) {
        
        btn.tag = idx;
        [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        CGFloat X = (margin1 + W )* idx + margin;
        
        btn.frame = CGRectMake(X, Y, W, H);
        
    }];
}
@end
